package com.prs.crm.action.sys;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;

import com.prs.crm.domain.sys.PasswordSet;
import com.prs.crm.service.sys.PasswordSetService;

public class PasswordSetAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private Integer[] ids;
	private PaginationSupport pagination;
	private PasswordSet passwordSet;
	private PasswordSetService passwordSetService;
	private String serCode;
	public String getSerCode() {
		return serCode;
	}
	public void setSerCode(String serCode) {
		this.serCode = serCode;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public PasswordSet getPasswordSet() {
		return passwordSet;
	}
	public void setPasswordSet(PasswordSet passwordSet) {
		this.passwordSet = passwordSet;
	}
	public PasswordSetService getPasswordSetService() {
		return passwordSetService;
	}
	public void setPasswordSetService(PasswordSetService passwordSetService) {
		this.passwordSetService = passwordSetService;
	}
	@Action("editPasswordSet")
	public String editPasswordSet(){
		this.passwordSet=this.getPasswordSetService().getPasswordSet(serCode);
		return SUCCESS;
	}
	@Action(value="savePasswordSet",results={
			@Result(name="success",type="redirect",location="editPasswordSet?serCode=${passwordSet.getType()}"),
			@Result(name="error",type="redirect",location="editPasswordSet?serCode=${passwordSet.getType()")
	})
	public String savePasswordSet(){
		PasswordSet pass=this.getPasswordSetService().getPasswordSet("ps01");
		if(pass==null){
			pass=new PasswordSet();
			pass.setType("ps01");
			pass.setPwdStrengthSave(passwordSet.getPwdStrengthSave());
			pass.setUpdateInitPwd(passwordSet.getUpdateInitPwd());
			this.getPasswordSetService().save(pass);
		}else{
			this.getPasswordSetService().submit(pass);
		}
		passwordSet=pass;
		return SUCCESS;
	}
}
